package cn.wolfcode.business.controller;

import cn.wolfcode.business.domain.BusAppointment;
import cn.wolfcode.business.service.AppointmentService;
import cn.wolfcode.common.core.controller.BaseController;
import cn.wolfcode.common.core.domain.AjaxResult;
import cn.wolfcode.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/business/appointment")
public class BusinessController extends BaseController {
    @Autowired
    private AppointmentService appointmentService;

    @GetMapping("/list")
    public TableDataInfo list(BusAppointment appointment){
        startPage();;
        List<BusAppointment> list = appointmentService.selectAppointmentList(appointment);
        return getDataTable(list);
    }
    @GetMapping("/{id}")
    public AjaxResult get(@PathVariable Long id){
        return AjaxResult.success(appointmentService.selectAppointmentById(id));
    }
    @PostMapping
    public AjaxResult save(@RequestBody BusAppointment appointment) {
        return toAjax(appointmentService.save(appointment));
    }
    @PutMapping
    public AjaxResult update(@RequestBody BusAppointment appointment) {
        return toAjax(appointmentService.update(appointment));
    }

    @DeleteMapping("/{ids}")
    public AjaxResult delete(@PathVariable Long[] ids) {
        return toAjax(appointmentService.deleteAppointmentByIds(ids));
    }
    @PatchMapping(value = "/{id}",headers = "cmd=arrival")
    public AjaxResult arrival(@PathVariable Long id) {
        return toAjax(appointmentService.arrival(id));
    }
    @PatchMapping(value = "/{id}",headers = "cmd=cancel")
    public AjaxResult cancel(@PathVariable Long id) {
        return toAjax(appointmentService.cancel(id));
        }
}

